//
//  ZTabBar.m
//  OC-weibo
//
//  Created by zero on 17/3/19.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "ZTabBar.h"

@interface ZTabBar()

@property (nonatomic,weak)UIButton *btn;

@end

@implementation ZTabBar

#pragma mark
#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        //  布局
        [self setupUI];
    }
    
    return self;
}

#pragma mark
#pragma mark - 布局
- (void)setupUI{
    
    UIButton *btn = [UIButton z_buttonWithNormalImageName:@"tabbar_compose_button" andHighLightedImageName:@"tabbar_compose_button_highlighted" andSelectedImageName:nil andImage:@"tabbar_compose_icon_add" andImageSelectedName:@"tabbar_compose_icon_add_highlighted" andTitle:nil andFrame:CGRectZero];
    
    self.btn = btn;
    
    [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];

    [self addSubview:btn];
}
#pragma mark
#pragma mark - 按钮点击事件
- (void)clickBtn{
    
    if (self.zTabBarBlocl) {
        
        self.zTabBarBlocl();
    }
}

#pragma mark
#pragma mark - 布局子控件
- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    
    CGFloat weigth = self.bounds.size.width / 5;
    CGFloat height = self.bounds.size.height;
    
    int index = 0;
    
    for (UIView *sub in self.subviews) {

        if ([sub isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            
            sub.frame = CGRectMake(index * weigth, 0, weigth, height);
            
            index += index == 1 ? 2 : 1;
            
        }
    }
    
    self.btn.frame = CGRectMake(0, 0, weigth, height);
    self.btn.center = CGPointMake(self.bounds.size.width * 0.5, height * 0.5);
    
}

@end
